/**
 * @title: DateComparator
 * @projectName magic-api
 * @Description TODO
 * @Author
 * @Date 2021/9/10 11:26
 */
package com.sugon.magicapi.module;

import org.springframework.stereotype.Component;
import org.ssssssss.magicapi.config.MagicModule;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

@Component
public class DateComparator implements MagicModule {

    public boolean comparenow(Timestamp reset_time){
        System.out.println(reset_time);
        Date now=new Date();
        int flag = reset_time.compareTo(now);
        if(flag>0)
        {
            return false;
        }else {
            return true;
        }
    }
    public Timestamp refreshRestTime(Timestamp reset_time,Long interval_time) throws ParseException {
        Date now=new Date();
        long interval = now.getTime() - reset_time.getTime();
        if(interval_time>=interval){
            Timestamp timestamp = new Timestamp(new Date(reset_time.getTime()+interval_time).getTime());
            return timestamp;
        }else{
            SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");
            SimpleDateFormat format_rest_fromat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String timestr = format.format(now);
            timestr=timestr+" 00:00:00";
            Date parse = format_rest_fromat.parse(timestr);
            return new Timestamp(parse.getTime()+24*60*60*1000);
        }
    }
    @Override
    public String getModuleName() {
        return "datecomparator";
    }
}
